#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
//https://www.luogu.com.cn/problem/P1019
using namespace std;

const int N = 30;


int n, ret;

int cnt[N];
std::string str[N];


void dfs(std::string path)
{
	//cout << "path:" << path << ' ' << "cnt:";
	//
	//for (int i = 1; i <= n; ++i)
	//{
	//	cout << cnt[i] << ' ';
	//}
	//
	//cout<< endl;
	if (path.size() > ret)ret = path.size();

	for (int i = 1; i <= n; ++i)
	{
		if (cnt[i] >=2)continue;

		int cur1 = path.size() - 1;
		int cur2 = 0;
		while (cur1 >= 1 && cur2 < str[i].size() - 1)
		{
			//cout << "inwhile:" << path.substr(cur1) << str[i].substr(0, cur2 + 1) << endl;
			if (path.substr(cur1) == str[i].substr(0, cur2+1))
			{
				cnt[i]++;
				dfs(path + str[i].substr(cur2+1));
				cnt[i]--;
			}
			cur1--, cur2++;
		}
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> str[i];
	char ch;
	cin >> ch;
	for (int i = 1; i <= n; ++i)
	{
		if (ch == str[i][0])
		{
			cnt[i]++;
			dfs(str[i]);
			cnt[i]--;
		}
	}

	cout << ret << endl;

	return 0;
}